<template>
  <hips-view sub-header-fixed>
    <hips-nav-bar
      slot="header"
      title="基础类"
      :back-button="{
        showLeftArrow: true,
      }"
      @nav-bar-back-click="$router.back()"
    />
    <demo-block title="getBaseInfo">
      <hips-button @click="getBaseInfoFuc">
        获取基础信息
      </hips-button>
    </demo-block>

    <demo-block title="getPushData">
      <hips-button @click="getPushDataFuc">
        获取推送信息
      </hips-button>
    </demo-block>

    <demo-block title="exit">
      <hips-button @click="exitFuc">
        退出子应用
      </hips-button>
    </demo-block>

    <demo-block title="switchFullscreen">
      <hips-button @click="exitFuc">
        全屏子应用
      </hips-button>
    </demo-block>

    <demo-block title="checkAppInstalled">
      <hips-button @click="checkAppInstalledFuc">
        是否安装某应用
      </hips-button>
    </demo-block>

    <demo-block title="switchOrientation">
      <hips-button @click="switchOrientationFuc">
        切换横竖屏
      </hips-button>
    </demo-block>

    <demo-block title="redirectApp">
      <hips-button @click="redirectAppFuc">
        跳转
      </hips-button>
    </demo-block>

    <demo-block title="getRedirectData">
      <hips-button @click="getRedirectDataFuc">
        跳转信息
      </hips-button>
    </demo-block>

    <demo-block title="openWebLink">
      <hips-button @click="openWebLinkFuc">
        打开链接
      </hips-button>
    </demo-block>

    <demo-block title="selectCountryCode">
      <hips-button @click="selectCountryCodeFuc">
        选择国家或地区代码
      </hips-button>
    </demo-block>

    <demo-block title="viewUserProfile">
      <hips-button @click="viewUserProfileFuc">
        查看用户信息
      </hips-button>
    </demo-block>
  </hips-view>
</template>

<script>
import BasicView from '@/mixin/basic-view';
import { Button } from '@hips/vue-ui';
import { Base } from '@hips/plugin-vue-jssdk';

const {
  getBaseInfo,
  getPushData,
  exit,
  switchFullscreen,
  checkAppInstalled,
  redirectApp,
  getRedirectData,
  openWebLink,
  selectCountryCode,
  viewUserProfile,
  switchOrientation,
} = Base;

export default {
  components: {
    [Button.name]: Button,
  },
  mixins: [ BasicView ],
  data() {
    return {
      currOrientation: 'portrait',
    };
  },
  methods: {
    getBaseInfoFuc() {
      getBaseInfo()
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },
    getPushDataFuc() {
      getPushData()
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },
    exitFuc() {
      exit();
    },
    switchFullscreenFuc() {
      switchFullscreen({
        fullScreen: true,
        hideNavbar: true,
      });
    },
    checkAppInstalledFuc() {
      checkAppInstalled({ bundleId: 'com.hand.hippius' })
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },
    switchOrientationFuc() {
      let orientation;
      if (this.currOrientation === 'landscape') {
        orientation = 'portrait';
      } else if (this.currOrientation === 'portrait') {
        orientation = 'landscape';
      }
      switchOrientation({ orientation }).then((res) => {
        console.log('res = ',res)
        this.currOrientation = orientation;
      });
    },
    redirectAppFuc() {
      redirectApp({ menuId: 'XX', args: { p: 'p' } });
    },
    getRedirectDataFuc() {
      getRedirectData()
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },
    openWebLinkFuc() {
      openWebLink('https://www.baidu.com');
    },
    selectCountryCodeFuc() {
      selectCountryCode();
    },
    viewUserProfileFuc() {
      viewUserProfile({
        tenantId: '280',
        employeeNum: 12008,
      });
    },
  },
};
</script>

<style lang="stylus"></style>
